﻿using System;
using System.Collections.Generic;

namespace ConsolePresentation
{
    public class TerritoriesView : ITerritoriesView
    {
        private readonly ITerritoriesService _service;

        public TerritoriesView(ITerritoriesService repository)
        {
            _service = repository;
        }

        public void ShowTerritories()
        {
            IEnumerable<Territory> territories = _service.GetTerritoriesFilterByDescription("");

            foreach (Territory territory in territories)
            {
                Console.WriteLine("{0}: {1}", territory.Id, territory.Description);
                Console.WriteLine("   {0}: {1}", territory.Region.Id, territory.Region.Description);
            }
        }

        public void ShowRegions(bool includeTerritories)
        {
            IEnumerable<Region> regions = _service.GetAllRegions();

            foreach (Region region in regions)
            {
                Console.WriteLine("{0}: {1}", region.Id, region.Description);

                if (!includeTerritories) continue;

                IEnumerable<Territory> territories = _service.GetTerritoriesByRegionId(region.Id);

                foreach (Territory territory in territories)
                {
                    Console.WriteLine("   {0}: {1}", territory.Id, territory.Description);
                }
            }
        }
    }
}